package com.ztgf.shopping.service.shop;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.BeanUtils;
import javax.annotation.Resource;
import com.ztgf.shopping.common.config.YmlConfig;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.ztgf.shopping.mapper.shop.ShopPayAmountLogMapper;
import com.ztgf.shopping.models.service.shop.IShopPayAmountLogService;
import com.ztgf.shopping.models.bo.shop.ShopPayAmountLogSaveBO;
import com.ztgf.shopping.models.dto.shop.ShopPayAmountLogDTO;

import java.math.BigDecimal;

/**
 * 店铺年费保证金支付日志控制器
 *
 * @author zhanghualang
 * @Date 2020-08-24 19:34:56
 */
@DubboService
public class ShopPayAmountLogServiceImpl extends ServiceImpl<ShopPayAmountLogMapper, ShopPayAmountLogDTO> implements IShopPayAmountLogService{

    @Resource
    private YmlConfig ymlConfig;

    @Override
    public boolean add(ShopPayAmountLogSaveBO saveBO) {
        ShopPayAmountLogDTO dto = new ShopPayAmountLogDTO();
        BeanUtils.copyProperties(saveBO,dto);
        Long id = ymlConfig.getPkId();
        dto.setId(id);
        return this.insert(dto);
    }

    @Override
    public ShopPayAmountLogDTO getLast(Long shopId, BigDecimal money, Integer type) {
        Wrapper<ShopPayAmountLogDTO> wrapper = new EntityWrapper<>();
        //类型 0保证金，1年费
        wrapper.eq("shop_id", shopId).eq("money", money).eq("status", 0).eq("type", type);
        wrapper.orderBy("create_time", false); //默认倒序
        wrapper.last("limit 1");

        return this.selectOne(wrapper);
    }

    @Override
    public ShopPayAmountLogDTO getBySerial(String paySerial) {
        Wrapper<ShopPayAmountLogDTO> wrapper = new EntityWrapper<>();
        wrapper.eq("pay_serial", paySerial);
        return this.selectOne(wrapper);
    }
}
